/**
 * @author ZCR
 * @create 2025/9/5 00:13
 */
public class Solution14 {
    public String longestCommonPrefix(String[] strs) {
        if (strs == null || strs.length == 0) {
            return "";
        }
        for (int i = 0; i < strs[0].length(); i++) {
            char c = strs[0].charAt(i);
            for (int j = 1; j < strs.length; j++) {
                if (i >= strs[j].length() || strs[j].charAt(i) != c) {
                    return strs[0].substring(0, i);
                }
            }
        }
        return strs[0];
    }

    public static void main(String[] args) {
        Solution14 solution14 = new Solution14();
        String[] strs = {"flower", "flow", "flight"};
        System.out.println(solution14.longestCommonPrefix(strs));
        strs = new String[]{"ab", "a"};
        System.out.println(solution14.longestCommonPrefix(strs));

    }
}
